package models

import (
	"192.168.1.75/go-pkg/helper"
	"gorm.io/gorm"
)

// MallServiceQAKeywords 商场服务常见问题关键字
type MallServiceQAKeywords struct {
	ID         string `json:"id" gorm:"column:id;primaryKey;type:int;size:64;comment:主键"`
	LocationID string `json:"location_id" gorm:"column:location_id;type:int;size:64;uniqueIndex:idx_keyword_question,priority:1"`
	QuestionID string `json:"question_id" gorm:"column:question_id;type:int;size:64;uniqueIndex:idx_keyword_question,priority:3;index:idx_question"`
	Keyword    string `json:"keyword" gorm:"column:keyword;type:string;size:30;uniqueIndex:idx_keyword_question,priority:2"`
	UseCount   int64  `json:"use_count" gorm:"column:use_count;type:bigint;comment:被使用总数，用于统计热度"`
	CreatedAt  int64  `json:"created_at" gorm:"autoCreateTime;column:created_at;type:int;size:64;comment:创建时间"`
	UpdatedAt  int64  `json:"updated_at" gorm:"autoUpdateTime;column:updated_at;type:int;size:64;comment:更新时间"`
}

func (MallServiceQAKeywords) TableName() string {
	return "mall_service_keywords"
}

// BeforeCreate 自增id
func (m *MallServiceQAKeywords) BeforeCreate(tx *gorm.DB) (err error) {
	if m.ID != "" {
		return nil
	}
	// 用户id为空时，自动添加用户id
	uuid, err := helper.UUID{}.String()
	if err != nil {
		return err
	}
	m.ID = uuid
	return nil
}

// 模式自动注册
func init() {
	Models = append(Models, &MallServiceQAKeywords{})
}
